#include <syslog.h>
#include <stdlib.h>
#include "bits.h"
#include "log.h"


void set_bits(u_int32 *p, u_short place, u_short type)
{
	u_int32 i = 0;
	if(place>=sizeof(u_int32))
		place = place%(sizeof(u_int32)*8);

	switch(type)
	{
		case BITS_ZERO:			
			(*p) = (~((i|BITS_ONE) << place))&(*p);
			break;
			
		case BITS_ONE:
			(*p) = ((i|BITS_ONE)<<place)|(*p);
			break;
		default:
			write_log(LOG_WARNING, NULL, "%s\n", "unknown type!");
			break;
	}	
}

int is_bit_zero(u_int32 *p, u_short place)
{
	u_int32 i = 1;
	if(!((*p)&(i<<place)))
		return 0;
	else
		return -1;
}

